import {
	post,
	get,
	put,
} from '@/utils/request.js'
import {
	BaseURL
} from '@/config/index.js'


/**
 * 分销订单详情(经纪人查看)
 */
export const agentOrderDetailApi = (params) => {
	return get('/order/agentOrderDetail', params)
}

/**
 * 购买订单详情(消费者查看)
 */
export const buyOrderDetailApi = (params) => {
	return get('/order/buyOrderDetail', params)
}

/**
 * 取消订单
 */
export const cancelOrderApi = (data) => {
	return post('/order/cancelOrder', data)
}

/**
 * 取消支付（用户主动调用）
 */
export const cancelPayApi = (data) => {
	return post('/order/cancelPay', data)
}

/**
 * 系统取消支付（倒计时到了调用）
 */
export const systemCancelPayApi = (data) => {
	return post('/order/systemCancelPay', data)
}

/**
 * 确认参与
 */
export const confirmJoinApi = (data) => {
	return post('/order/confirmJoin', data)
}

/**
 * 创建订单
 */
export const createOrderApi = (data) => {
	return post('/order/createOrder', data)
}

/**
 * 创建拼团
 */
export const createGroupBuyOrder = (data) => {
	return post('/order/createGroupBuyOrder', data)
}

/**
 * 创建0元拼团
 */
export const createZeroGroupBuyOrder = (data) => {
	return post('/order/createZeroGroupBuyOrder', data)
}

export const getGroupBuyMembersApi = (data)=>{
	return get('/order/groupMembers',data);
}

/**
 * 获取用户已下单该活动的数量(选择下单数量需要显示)
 */
export const getActiveOrderNumApi = (params) => {
	return get('/order/getActiveOrderNum', params)
}

/**
 * 我的活动的订单管理的统计
 */
export const getOrderStatisticsApi = (params) => {
	return get('/order/getOrderStatistics', params)
}

/**
 * 报名详情（报名订单）
 */
export const orderEnrollActiveDetailApi = (params) => {
	return get('/order/orderEnrollActiveDetail', params)
}

/**
 * 拼团详情
 */
export const groupBuyOrderDetailApi = (params,options) => {
	return get('/order/groupBuyOrderDetail', params,options||{})
}

/**
 * 分销的订单列表(经纪人查看)
 */
export const pageAgentOrderApi = (params) => {
	return get('/order/pageAgentOrder', params)
}

/**
 * 购买的订单列表(消费者查看)
 */
export const pageBuyOrderApi = (params) => {
	return get('/order/pageBuyOrder', params)
}

/**
 * 卖出的订单列表(商家查看)
 */
export const pageSellOrderApi = (params) => {
	return get('/order/pageSellOrder', params)
}

/**
 * 卖出订单详情(商家查看)
 */
export const sellOrderDetailApi = (params) => {
	return get('/order/sellOrderDetail', params)
}

/**
 * 立即支付，唤起第三方支付
 */
export const orderPayApi = (data) => {
	return post('/order/pay', data)
}
export const orderToPay = (data) => {
	return post('/order/toPay', data)
}
/**
 * 获取订单核销二维码
 */
export const getVerifyCodeImgApi = (verifyCode) => {
	return get(`/order/getVerifyCodeImg?verifyCode=${verifyCode}`)
}

/**
 * 查单（监听用户唤醒支付成功之后调用）
 */
export const queryOrderPay = (data) => {
	return post('/order/queryOrderPay', data)
}

/**
 * 获取活动红包可用状态
 */
export const getRedAvailableStatusApi = (data) => {
	return get('/order/getRedAvailableStatus', data)
}

/**
 * 导出活动订单，预先调用判断是否有异常
 * checkState： 预检查标识:0-需要，1-不需要
 * @@return {文件流}
 */
export const preExportApi = (data) => {
	return get('/order/exportOrder', data)
}

// 导出活动订单地址
export const exportOrderUrl = (data) => {
	let params = ''
	for (const key in data) {
		if (data.hasOwnProperty(key)) {
			params += `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}&`
		}
	}
	return `${BaseURL}/order/exportOrder?${params}`
}

// 获取最近10个订单用户头像（气泡）
export const getOrderAvatar = (options = {}) => {
	return get('/order/getLastAvatar',{},options)
}

export const getPendingGroupBuyOrdersApi = (data) => {
	return get('/order/pendingGroupOrders',data)
}
